// Seir programming Editor
// Copyright (c) <2007> <David Torres>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

/*
 * Created by SharpDevelop.
 * User: David William Torres
 * Date: 5/29/2007
 * Time: 2:43 PM
 * 
 */

using System;
using Gtk;
using GtkSourceView;

namespace Seir
{
	public class sView : Gtk.ScrolledWindow
    {
        #region Variables

        private GtkSourceView.SourceView s_EditView = null;
		private GtkSourceView.SourceBuffer s_EditBuffer = null;
		private sDocument s_Document = null;

        #endregion

        #region Constructor

        public sView()
        {
            initComponents();
        }

        #endregion

        #region Getters and Setters

        public sDocument Document
		{
			get
            {
                return s_Document;
            }
			set
            {
                s_Document = value;
            }
        }

        public GtkSourceView.SourceView EditView
		{
			get
            {
                return s_EditView;
            }
		}
		
		public GtkSourceView.SourceBuffer SourceBuffer
		{
			get
            {
                return s_EditBuffer;
            }
        }

        #endregion

        #region Initialization

        // Initialization of components and their
        // preliminary attribute settings
        protected void initComponents()
		{
			SourceLanguagesManager slm = new SourceLanguagesManager();
			SourceLanguage theSl = null;

			if(slm == null)
				Console.WriteLine("SourceLanguagesManager is NULL :(");
			
			if(slm.AvailableLanguages == null)
				throw new System.Exception("Source Language Manger.AvailableLanguages did not initialize or is not valid.");
			
			foreach(SourceLanguage sl in slm.AvailableLanguages)
			{
				Console.WriteLine("Now looking at: {0}.", sl.Name);
                // Probably need a 'case' statement here to change sl according to file extension
				if(sl.Name.CompareTo("C#") == 0)
				{
					theSl = sl;
					break;
				}
			}
			
			if(theSl != null)
			{
				// Instantiate the SourceBuffer
				s_EditBuffer = new SourceBuffer(theSl);
					
				// Instantiation of the TextView
				s_EditView = new SourceView(s_EditBuffer);
			}
			else
			{
				// Instantiation of the TextView
				s_EditView = new SourceView();
			}

			Console.WriteLine("Compare worked");

			// Settings of Height and Width
			s_EditView.WidthRequest = 400;
			s_EditView.HeightRequest = 300;
			s_EditView.ShowLineNumbers = true;
			
			// Embedd in the ScrollWindow
			this.Add(s_EditView);
        }

        #endregion

        // Returns an Array of SourceLanguages
		public GtkSourceView.SourceLanguage[] GetAllAvailableLanguages()
		{
			SourceLanguagesManager slm = new SourceLanguagesManager();			
			return slm.AvailableLanguages;
		}
	}
}
